package com.foreveross.action.weixin;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.foreveross.common.CommonUtil;
import com.foreveross.common.Constants;
import com.foreveross.common.Exception.ExceptionConstant;
import com.foreveross.service.HouseLeaseService;
import com.foreveross.service.LogService;
import com.foreveross.util.AuthUtil;
import com.foreveross.util.FileUtil;
import com.foreveross.vo.HouseLease;
import com.foreveross.vo.HrFavorable;
import com.foreveross.vo.common.FileVo;
import com.foreveross.vo.common.PageVo;
import com.foreveross.vo.common.ResultVo;
/**
 * 房屋出租
 * @author Administrator
 *
 */
@Controller
@RequestMapping(value = "/weixin/HouseLeaseController")
public class HouseLeaseController {

	private Logger log = Logger.getLogger(HouseLeaseController.class);

	@Resource
	private HouseLeaseService houseLeaseService;

	@Resource
	private LogService logService;
	
	/**
	 * 获取房屋出租列表
	 * @param request
	 * @param response
	 * @param housingArea
	 * @param houseId
	 * @param title
	 * @param rent
	 * @param text
	 * @param currentPage
	 * @param pageSize
	 */
	@RequestMapping(method = RequestMethod.POST, value = "/getHouseLeaseList")
	public void getHouseLeaseList(HttpServletRequest request,
			HttpServletResponse response,String housingArea,String houseId,
			String title,String rent,String text,
			String currentPage,String pageSize) {
		ResultVo resultVo = new ResultVo();
		try {
			int total = (int)houseLeaseService.getHouseLeaseListCount(housingArea,title,houseId,null,null,text,null);
			PageVo<HouseLease> pageVo = new PageVo<HouseLease>(currentPage,total,pageSize);
			List<HouseLease> list = houseLeaseService.getHouseLeaseList(housingArea,title,houseId,null,null,text,pageVo.getpageIndex(),pageVo.getpageSize(),null);
			//图片地址转换
			List<HouseLease> listOut = new ArrayList<HouseLease>(); 
			for (HouseLease houseLease : list){
				List<FileVo> fileVoList = FileVo.getFileVoList(request, houseLease.getImage());
				houseLease.setOther(fileVoList);
				listOut.add(houseLease);
			}			
			pageVo.setData(list);
			resultVo.setSuccess(true);
			resultVo.setData(pageVo);
			log.info("房屋出租 查看成功!");
		} catch (Exception e) {
			resultVo.setSuccess(false);
			resultVo.setMessage("房屋出租  查看失败");
			log.error("房屋出租 查看失败!", e);
		}
		List listz = Arrays.asList("messageHouses","newsHouses","optimizedHouses");
		CommonUtil.PrintWriterResultWithJSON(response, resultVo,listz);
	}
	
	
	/**
	 * 查看房屋出租详情
	 * @param request
	 * @param response
	 * @param id
	 */
	@RequestMapping(method = RequestMethod.POST, value = "/getHouseLeaseById")
	public void getHouseLeaseById(HttpServletRequest request,
			HttpServletResponse response,String id) {
		ResultVo resultVo = new ResultVo();
		try {
			HouseLease houseLease = houseLeaseService.getHouseLeaseById(id);			
			List<FileVo> fileVoList = FileVo.getFileVoList(request, houseLease.getImage());
			resultVo.setOther(fileVoList);
			resultVo.setSuccess(true);
			resultVo.setData(houseLease);
			log.info("房屋出租 查看成功!");
		} catch (Exception e) {
			resultVo.setSuccess(false);
			resultVo.setMessage("房屋出租  查看失败");
			log.error("房屋出租 查看失败!", e);
		}
		List listz = Arrays.asList("messageHouses","newsHouses","optimizedHouses");
		CommonUtil.PrintWriterResultWithJSON(response, resultVo,listz);
	}
	
}
